package com.burgeon.backend.SHOPBACKEND.controller;

import com.burgeon.backend.SHOPBACKEND.entity.GroupData;
import com.burgeon.backend.SHOPBACKEND.service.BackendGroupService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("shopbackent/group")
public class BackendGroupController extends BaseController {

    @Autowired
    private BackendGroupService backendGroupService;

    @RequestMapping("getimg")
    public ResponseResult<String> getGroupImg(String account) {
        String data = backendGroupService.getImg(account);

        return new ResponseResult<String>(SUCCESS,data);
    }

    @RequestMapping("upimg")
    public ResponseResult<String> groupImg(@RequestParam(value = "file") MultipartFile file, String account) {
        String data = backendGroupService.upImg(file, account);

        return new ResponseResult<String>(SUCCESS,data);
    }


    @RequestMapping("use")
    public ResponseResult<Void> isUse(String id, String isUse) {
        System.err.println("id="+id+"isuse="+isUse);
        backendGroupService.isUse(id, isUse);
        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("item")
    public ResponseResult<HashMap> getItem(String id) {
        HashMap data = backendGroupService.getItem(id);

        return new ResponseResult<HashMap>(SUCCESS, data);
    }


    @RequestMapping("del")
    public ResponseResult<Void> DelData(String id, String account) {
        backendGroupService.deleteGroup(id, account);

        return new ResponseResult<>(SUCCESS);
    }

    @RequestMapping("list")
    public ResponseResult<List<GroupData>> GroupList(String account) {

        List<GroupData> data = backendGroupService.getData(account);

        return new ResponseResult<List<GroupData>>(SUCCESS, data);
    }

    @RequestMapping("add")
    public ResponseResult<Void> AddData(GroupData groupData) {

        backendGroupService.createGroup(groupData);
        return new ResponseResult<>(SUCCESS);
    }

}
